<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="业务组工作台">
    <!--suppress ALL -->
     <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/proxy/selectProxyPage">
         <ul class="panel-content">
             <li>
                 <div class="form-actions">
                     <div class="control-group controls span5">
                         <input type="text" class="input-normal  input-pad" name="name"
                                placeholder="请输入关键字搜索">
                     </div>
                     <div class="control-group controls span8">
                         <label class="time-label control-label" style="line-height: 40px;">请选择状态：</label>
                         <select name="status" class="input-normal" id="status">
                             <option value="">请选择状态</option>
                             <option value="">全部状态</option>
                             <option value="等待提交委托书">等待提交委托书</option>
                             <option value="等待指派采样人员">等待指派采样人员</option>
                             <option value="采样中">采样中</option>
                             <option value="等待指派实验人员">等待指派实验人员</option>
                             <option value="实验分析">实验分析</option>
                             <option value="编写报告">编写报告</option>
                             <option value="一审中">一审中</option>
                             <option value="二审中">二审中</option>
                             <option value="发放打印">发放打印</option>
                             <option value="已完成">已完成</option>
                         </select>

                     </div>
                     <button type="submit" class="button  button-primary">
                         查询
                     </button>

                     <div class="contract-button">
                         <a class="button button-primary" href="${basepath}/rest/manage/proxy/toAdd">
                             新增
                         </a>
                     </div>

                 </div>
             </li>
         </ul>
     </form>
<#----------------------------------------------新增表单start--------------------------------------------------------->
<div id="addContent" style="display:none;">
    <form id="addForm" class="form-horizontal" action="${basepath}/rest/manage/handlelog/insertHandleLog" method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID"/>
        <div class="row">
            <div class="control-group">
                <label class="control-label span16">
                    执行动作：
                </label>
                <div class="controls bui-form-group-select">
                    <select class="span7" name="actionName">
                        <option>请选择执行动作</option>
                        <option value="提交">提交</option>
                    </select>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">选择指派人员：</label>

                <div class="controls bui-form-group-select">
                    <div id="send-people" class="people">
                        <input type="hidden" id="send-peopleName" name="userID" data-rules="{required : true}">
                    </div>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------新增表单 end---------------------------------------------------------->
<div id="grid"></div>
<script>
    //查询登陆用户的名称
    var userID = "", isHeadman = "";
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/manage/user/selectLoginUser',
        success: function (data) {
            userID = data.data.id;
            isHeadman = data.data.isHeadman;
            query();
        }
    })
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            Select = BUI.Select, columns = "", store = "", grid = "";

    function query() {
        columns = [
            {
                title: '序号',
                elCls: 'center',
                dataIndex: 'id',
                width: '5%',
                renderer: function (value, obj, index) {
                    return index + 1;
                }
            },
            {title: '客户名称', dataIndex: 'customerName', elCls: 'center', width: '10%'},
            {title: '合同名称', dataIndex: 'contractName', elCls: 'center', width: '10%'},
            {title: '委托书名称', dataIndex: 'name', elCls: 'center', width: '10%'},
            {title: '委托书编号', dataIndex: 'sno', elCls: 'center', width: '10%'},
            {title: '录入时间', dataIndex: 'createTime', elCls: 'center', width: '10%'},
            {
                title: '事件跟踪', dataIndex: 'id', elCls: 'center', width: '5%', renderer: function (value) {
                    return '<a href="${basepath}/rest/manage/proxy/toEventList?proxyID=' + value + '">查看</a>';
                }
            },
            {title: '业务员', dataIndex: 'userName', elCls: 'center', width: '10%'},
            {
                title: '委托书状态',
                dataIndex: 'status',
                elCls: 'center',
                width: '10%',
                renderer: function (value) {
                    switch (value) {
                        case '全部状态':
                            return '全部状态';
                            break;
                        case '等待提交委托书':
                            return '等待提交委托书';
                            break;
                        case '等待指派采样人员':
                            return '等待指派采样人员';
                            break;
                        case '采样中':
                            return '采样中';
                            break;
                        case '等待指派实验人员':
                            return '等待指派实验人员';
                            break;
                        case '实验分析':
                            return '实验分析';
                            break;
                        case '编写报告':
                            return '编写报告';
                            break;
                        case '一审中':
                            return '一审中';
                            break;
                        case '二审中':
                            return '二审中';
                            break;
                        case '发放打印':
                            return '发放打印';
                            break;
                        case '已完成':
                            return '已完成';
                            break;
                    }
                }
            },
            {
                title: '留言备注', dataIndex: 'remark', elCls: 'center', width: '10%', renderer: function (value) {
                    return value == "" || value == null ? "____" : value;
                }
            },
            {
                title: '操作', elCls: 'center', dataIndex: 'id', width: '10%', renderer: function (value, obj) {
                    if (obj.status == '等待提交委托书') {
                        return '<a href="javascript:operating(' + value + ')">操作</a>&nbsp;&nbsp;<a href="${basepath}/rest/manage/proxy/toEdit?id=' + value + '">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    } else {
                        return '<a href="${basepath}/rest/manage/proxy/toEdit?id=' + value + '">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    }

                }
            }
        ];
        var url = "";
        isHeadman == 'n' ? url = '/rest/manage/proxy/selectProxyPage?userID=' + userID + '' : url = '/rest/manage/proxy/selectProxyPage'
        store = new Store({
            url: url,
            autoLoad: true, //自动加载数据
            params: { //配置初始请求的参数
                length: '10',
                status: $("#status").val()
            },
            pageSize: 10,	// 配置分页数目
            root: 'list',
            totalProperty: 'total'
        });
        grid = new Grid.Grid({
            render: '#grid',
            columns: columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar: {
                pagingBar: true
            }
        });

        grid.render();
    }

    /**********************模糊搜索*************************/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /**********************删除单个委托书信息*************************/
    function deleteOne(value) {
        BUI.Message.Confirm('确定要执行删除操作？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/proxy/deleteJson',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = new Object();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }

    /*********************************操作***********************************/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();

    var addDialog = new BUI.Overlay.Dialog({
        title: '操作',
        width: 500,
        height: 280,
        contentId: 'addContent',
        success: function () {
            if (addForm.isValid()) {
                addForm.submit();
            } else {
                addForm.valid();
            }
        }
    });

    function operating(id) {
        addForm.clearFields();
        addDialog.show();
        $("input[name='proxyID']").val(id);
    }

    /*********************************多选框查询人员***********************************/
            //一级商品目录下拉
    var pStore = new Store({
                url: '${basepath}/rest/manage/user/selectAllList?role_name=中枢组&isHeadman=n',
                autoLoad: true,
                root: 'data',
            });
    var pSelect = new Select.Select({
        render: '#send-people',
        valueField: '#send-peopleName',
        list: {
            itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
            idField: 'id'
        },
        multipleSelect: true,
        store: pStore
    }).render();

</script>

</@page.pageBase>
